<?php
//dump($data);
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <include file="Common/meta" />
    <title>我的消息 - {$_ENV['site'][0]['title']}</title>
    <include file="Common/link" />
</head>
<body>
<div class="layout-header">
    <div class="container">
        <h1 class="title">我的消息</h1>
        <a class="header-back" href="/user/personCenter"><i class="icon icon-left"></i></a>
    </div>
</div>
<div class="layout-body">
        <section>
            <if condition="count($data['list']) eq 0">
                <div id="search-empty" class="content-empty show">
                    <div class="picture"></div>
                    <div class="no-data">暂时没有任何消息</div>
                </div>
            </if>
            <ul class="list user-msg-list">
                <foreach name="data['list']" item="msg">
                    <li class="list-item msg-item" data-id="{$msg['id']}">
                        <div class="msg-left">
                            <div class="msg-title">{$msg['title']}
                                <if condition="$msg['status'] eq 0">
                                    <i class="icon-new"></i>
                                </if>
                            </div>
                            <div class="msg-content">{$msg['contain']}</div>
                        </div>
                        <div class="msg-right">
                            <div class="operate">
                                <a class="delete-msg" href="#">删除</a>
                                <if condition="$msg['status'] eq 0">
                                    <a class="msg-read" href="#">标为已读 </a>
                                </if>
                            </div>
                            <div class="msg-time">{$msg['create_time']|strtotime|date="Y-m-d H:i",###}</div>
                        </div>
                    </li>
                </foreach>
            </ul>
    </section>
</div>
<include file="Common/script" />
<script>
    // 删除消息
    $(document).on('click', '.delete-msg', function (e) {
        e.preventDefault();

        var $this = $(this);
        var $item = $this.closest('.msg-item');
        var id = $item.data('id');

        $.ajax({
            url: '/user/msgDelete',
            data: {
                id: id
            },
            type: 'POST',
            dataType: 'json',
            success: function (obj) {
                if (obj.code === 0) {
                    location.reload(true);
                } else {
                    eui.msg('操作失败');
                }
            },
            error: function () {
                eui.msg('系统出错');
            }
        });
    });

    // 标识为已读
    $(document).on('click', '.msg-read', function (e) {
        e.preventDefault();

        var $this = $(this);
        var $item = $this.closest('.msg-item');
        var id = $item.data('id');

        $.ajax({
            url: '/user/msgRead',
            data: {
                id: id
            },
            type: 'POST',
            dataType: 'json',
            success: function (obj) {
                if (obj.code === 0) {
                    location.reload(true);
                } else {
                    eui.msg('操作失败');
                }
            },
            error: function () {
                eui.msg('系统出错');
            }
        });
    });

</script>
</body>
</html>

